package cn.lanqiao.demo.dao;


import cn.lanqiao.demo.entity.Student;
import cn.lanqiao.demo.vo.StudentVaccineVo;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface StudentDao {

    //根据sno查询学生信息
    @Select("select Sno,Sname,Cname,Sage,Sbirth,Ssex,image,inoculated from student s LEFT JOIN vaccine v on v.Vno = s.Sno where sno = #{sno}")
    public StudentVaccineVo getStudentBySno(String sno);

    //查询所有学生信息
    @Select("select Sno,Sname,Cname,Sage,Sbirth,Ssex,image,inoculated from student s LEFT JOIN vaccine v on v.Vno = s.Sno")
    public List<StudentVaccineVo> getAllStudents();

    //添加学生信息
    @Insert("insert into student(Sno,Sname,Cname,Sage,Sbirth,Ssex,image) values(#{Sno},#{Sname},#{Cname},#{Sage},#{Sbirth},#{Ssex},#{image})")
    public int addStudent(Student student);

    //删除学生信息
    @Delete("delete from student where Sno=#{sno}")
    public int deleteStudent(String sno);

    //修改学生信息
    @Update("update student set Sno=#{student.Sno},Sname=#{student.Sname},Cname=#{student.Cname},Sage=#{student.Sage},Sbirth=#{student.Sbirth},Ssex=#{student.Ssex},image=#{student.image} where Sno=#{student.sno}")
    public int updateStudent(Student student);

    //学生分页方法
    @Select("select * from student")
    public List<Student> getList();

}
